package com.miao.service.impl;

import com.miao.dao.OrderDao;
import com.miao.entity.Order;
import com.miao.service.OrderService;
import com.miao.util.BeanCopyUtil;
import com.miao.util.PaymentID;
import com.miao.vo.OrderVo;
import com.miao.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrederServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;


    @Override
    public ResultVo<OrderVo> selectCommentAllByPartTimeId(Integer orderId) {
        int order=orderDao.findOderId(orderId);
        OrderVo orderVo=new OrderVo();
        BeanCopyUtil.copyProperties(order,orderVo);
        return ResultVo.success(orderVo);
    }

    @Override
    public ResultVo<OrderVo> addOrder(Order order){
        PaymentID paymentID=new PaymentID();
        String demg=paymentID.setID();
        order.setOrderNo(demg);
        order.setCreateTime(System.currentTimeMillis());
        int addResult = orderDao.orderAdd(order);
        ResultVo resultVo= addResult== 1 ? ResultVo.success("添加成功"):ResultVo.failed("添加失败");
        return resultVo;
    }

//    @Override
//    public ResultVo<OrderVo> addOrder(Order order) {
//        int addResult = orderDao.orderAdd(order);
//        ResultVo resultVo= addResult== 1 ? ResultVo.success("添加成功"):ResultVo.failed("添加失败");
//        return resultVo;
//    }

    @Override
    public ResultVo<OrderVo> delOrder(OrderVo orderVo) {
        int delResult = orderDao.orderDel(orderVo.getOrderId());
        ResultVo resultVo = delResult == 1 ? ResultVo.success("删除成功") : ResultVo.failed("删除失败");

        return resultVo;
    }



    @Override
    public ResultVo<OrderVo> editOrder(Order order) {
        int editResult = 0;
        ResultVo resultVo = null;
        order.setUpdateTime(System.currentTimeMillis());
        editResult = orderDao.orderEdit(order);
        resultVo=editResult==1?ResultVo.success("编辑成功"):ResultVo.failed("编辑失败");
        return resultVo;
    }

    @Override
    public ResultVo<OrderVo> listOrder(Order order) {
        int listResult=0;
        ResultVo resultVo=null;
//        listResult=orderDao.orderList(order);
        resultVo=listResult==1?ResultVo.success("渲染成功"):ResultVo.failed("渲染失败");
        return resultVo;
    }
}
